package com.ktwlsoft.archivemanage.domain.business.repositoryService.study;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.entity.study.StudyComment;
import com.ktwlsoft.archivemanage.domain.dao.repository.study.StudyCommentMapper;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程评论
 *
 * @author Name on 2019/12/25 9:32
 * @version 1.0
 */
@Service
public class StudyCommentRepositoryService {
    @Getter
    private final StudyCommentMapper studyCommentMapper;

    public StudyCommentRepositoryService(StudyCommentMapper studyCommentMapper) {
        this.studyCommentMapper = studyCommentMapper;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_comment
     *
     * @mbg.generated
     */
    public int deleteByPrimaryKey(Long id) {
        return studyCommentMapper.deleteByPrimaryKey(id);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_comment
     *
     * @mbg.generated
     */
    public int insert(StudyComment record) {
        return studyCommentMapper.insert(record);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_comment
     *
     * @mbg.generated
     */
    public StudyComment selectByPrimaryKey(Long id) {
        return studyCommentMapper.selectByPrimaryKey(id);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_comment
     *
     * @mbg.generated
     */
    public List<StudyComment> selectAll() {
        return studyCommentMapper.selectAll();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_comment
     *
     * @mbg.generated
     */
    public int updateByPrimaryKey(StudyComment record) {
        return studyCommentMapper.updateByPrimaryKey(record);
    }

    /**
     * 查询集合 on 2019/12/25 9:42
     *
     * @param jsonObject jsonObject
     * @return List<StudyComment>
     */
    public List<StudyComment> findList(JSONObject jsonObject) {
        return studyCommentMapper.findList(jsonObject);
    }

    /**
     * 查询分页 on 2019/12/25 9:42
     *
     * @param jsonObject jsonObject
     * @return List<StudyComment>
     */
    public PageInfo<StudyComment> findPage(int pn, int pageSize, JSONObject jsonObject) {
        PageHelper.startPage(pn, pageSize);
        return new PageInfo<>(studyCommentMapper.findList(jsonObject));
    }

    /**
     * 课程评论分页
     *
     * @param pn
     * @param pageSize
     * @param classId
     * @return
     */
    public PageInfo<StudyComment> selectByClassId(int pn, int pageSize, Long classId) {
        PageHelper.startPage(pn, pageSize);
        PageInfo<StudyComment> pageInfo = new PageInfo<>(studyCommentMapper.selectByClassId(classId));
        return pageInfo;
    }
}